/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved.
 */

package com.huawei.aiservice.entity.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * MultiResponse
 *
 * @author chenpingui
 * @since 2012-12-22（或版本号）
 */
@Data
public class MultiResponse<T> {
    @JsonProperty("code")
    private Integer code;

    @JsonProperty("message")
    private String message;

    @JsonProperty("result")
    private T result;

    /**
     * MultiResponse
     */
    public MultiResponse() {
    }

    /**
     * MultiResponse
     *
     * @param code    code
     * @param message message
     * @param result  result
     * @return MultiResponse<T>
     */
    public MultiResponse(Integer code, String message, T result) {
        this(code, message);
        this.result = result;
    }

    /**
     * MultiResponse
     *
     * @param code    code
     * @param message message
     * @return MultiResponse<T>
     */
    public MultiResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * code
     *
     * @param code code
     * @return MultiResponse<T>
     */
    public MultiResponse code(Integer code) {
        this.code = code;
        return this;
    }

    /**
     * message
     *
     * @param message message
     * @return MultiResponse<T>
     */
    public MultiResponse message(String message) {
        this.message = message;
        return this;
    }

    /**
     * success
     *
     * @param result result
     * @param <T>    T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> success(T result) {
        return new MultiResponse<>(200, "success", result);
    }

    /**
     * success
     *
     * @param message message
     * @param <T>     T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> success(String message) {
        return new MultiResponse<>(200, message, null);
    }

    /**
     * success
     *
     * @param message message
     * @param result result
     * @param <T>     T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> success(String message, T result) {
        return new MultiResponse<>(200, message, result);
    }

    /**
     * fail
     *
     * @param <T> T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> fail() {
        return new MultiResponse<>(500, "fail", null);
    }

    /**
     * fail
     *
     * @param message message
     * @param <T>     T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> fail(String message) {
        return new MultiResponse<>(500, message, null);
    }

    /**
     * fail
     *
     * @param message message
     * @param code    code
     * @param <T>     T
     * @return MultiResponse<T>
     */
    public static <T> MultiResponse<T> fail(int code, String message) {
        return new MultiResponse<>(code, message, null);
    }
}

